package org.example;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Date;

public class VelocityExample {
    public static void main(String[] args) {
        // 1. 初始化 Velocity 引擎
        VelocityEngine ve = new VelocityEngine();
        ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        ve.init();

        // 2. 创建上下文（Context），用于填充模板变量
        VelocityContext context = new VelocityContext();

        // 3. 加载模板
        Template template = ve.getTemplate("templates/template.json");

        context.put("myname", "john-scy");
        context.put("bdpmscycleval", "202508");

        // 4. 合并模板与数据
        StringWriter writer = new StringWriter();
        template.merge(context, writer);

        // 5. 输出结果
        System.out.println(writer.toString());
    }
}